home *** CD-ROM | disk | FTP | other *** search
-
- {****************************************************************************
- * Program: TPDemo1.pas *
- * Author: Marty Balash *
- * Date: 03/02/91 *
- * Remarks: How to display an .MJB image using Turbo Pascal *
- * *
- * NOTE: o - Create (partial screen) image using PCX2BGI.EXE *
- * (DEMO.PCX was used to create the images for this program) *
- * o - Run TPCONV.EXE using .MJB file from PCX2BGI.EXE to create *
- * .HDR and .DAT files for input to your Turbo Pascal program *
- * and to get the size of the array to hold the image *
- * o - Display the image as demonstrated in this code *
- * o - Send $15.00 to: *
- * *
- * Marty Balash *
- * 2 Pinecrest Dr. *
- * Prospect CT 06712 *
- ****************************************************************************}
-
- program tpdemo;
- uses crt,graph;
-
- {
- *** NOTE: Following two constants will be needed for each image loaded ***
- }
- const basefn = 'BGI1'; { Filename without HDR/DAT ext }
- const imsize = 7702; { 7702 = Size of image reported by TPCONV.EXE }
-
- type imagehdr = record { imagehdr - Describes header info }
- id : array [1..8] of char; { id - This should be 'PCX2BGI' }
- size : word; { size - For TC programs (not needed) }
- palette : palettetype; { palette - Use SetAllPalette to set }
- end;
-
- type imagedata = { A type (of the correct size) is needed }
- array[1..imsize] of byte; { for each different image loaded }
-
- var
- hdr:imagehdr; { hdr - Verify fmt & get palette to use }
- dat:imagedata; { dat - Display this buffer with PutImage }
-
- procedure openegascreen; { Open 640x350 16-color EGA screen }
- var
- driver,mode,result:integer;
- begin
- driver := ega;
- mode := egahi;
- initgraph(driver,mode,'');
- result := graphresult;
- if result <> grok then
- begin
- write('ERROR: ',grapherrormsg(result));
- exit;
- end;
- end;
-
- procedure readimage;
- var
- hdrhandle:file of imagehdr; { Header will be retrieved in one read }
- dathandle:file of imagedata; { Data will be retrieved in one read }
- hdrname:string[7]; { For testing file format }
- hdrfn:string[12];
- datfn:string[12];
- begin
- hdrfn:=basefn+'.HDR'; { Create filenames }
- datfn:=basefn+'.DAT';
- assign(hdrhandle,hdrfn); { Open the header file ... }
- {$I-}
- reset(hdrhandle);
- {$I+}
- if ioresult <> 0 then
- exit;
- read(hdrhandle,hdr); { Read header }
- close(hdrhandle); { Close header file }
- hdrname:=hdr.id[1]+hdr.id[2]+hdr.id[3]+hdr.id[4]+hdr.id[5]+hdr.id[6]+hdr.id[7];
- if hdrname <> 'PCX2BGI' then { Verify file format }
- exit;
- setallpalette(hdr.palette); { Set palette to image palette }
- assign(dathandle,datfn); { Open the data file ... }
- {$I-}
- reset(dathandle);
- {$I+}
- if ioresult <> 0 then
- exit;
- read(dathandle,dat); { Read data }
- close(dathandle); { Close data file }
- end;
-
- begin { MAIN PROGRAM }
- openegascreen; { Open EGA hi-res screen }
- readimage; { Read image from disk }
- putimage(0,0,dat,NormalPut); { Put the image on the screen }
- repeat until keypressed; { Wait until keypress }
- closegraph; { Done }
- writeln('Created with LBM2BGI.EXE by Marty Balash');
- end.
-